package com.atomdayl.domain.therecipe;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;

import com.atomdayl.domain.therecipe.activity.BaseActivity;
import com.atomdayl.domain.therecipe.activity.DishDetailActivity;
import com.atomdayl.domain.therecipe.activity.UploadActivity;
import com.atomdayl.domain.therecipe.adapter.MyRecommendedAdapter;

public class MainActivity extends BaseActivity implements View.OnClickListener {
    private ListView list_recommended_today;
    private MyRecommendedAdapter myRecommendedAdapter;
    private ImageView search_add;
    private ImageView search_person;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initViews();
    }

    /**
     * 初始化视图
     */
    private void initViews() {
        search_add = (ImageView) findViewById(R.id.search_add);
        search_add.setOnClickListener(this);
        search_person = (ImageView) findViewById(R.id.search_person);
        search_person.setOnClickListener(this);


        list_recommended_today = (ListView) findViewById(R.id.list_recommended_today);
        list_recommended_today.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                startActivity(new Intent(MainActivity.this, DishDetailActivity.class));
            }
        });
        myRecommendedAdapter = new MyRecommendedAdapter(this);
        list_recommended_today.setAdapter(myRecommendedAdapter);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.search_add:
                startActivity(new Intent(this, UploadActivity.class));
                break;
            case R.id.search_person:
                startActivity(new Intent(this, LoginActivity.class));
                break;
        }
    }
}
